import {EventDispatcher, Utils} from '../common.js'
import SettingEvent from './setting-event.js'
import Layout from '../layout.js'

export default class Setting extends EventDispatcher {
    constructor() {
        super(new SettingEvent());
        const _ui = this._ui = Layout.CreateSetting('modal-1');

        // logic
        this.myModal = new bootstrap.Modal(_ui);
        _ui.addEventListener('hidden.bs.modal', () => {
            _ui.remove();
        })
        _ui.addEventListener('shown.bs.modal', () => {
        })
        _ui.inputElem.addEventListener('click', () => {
            this._event.DispatchEvent(SettingEvent.EVT_SETTING_ARCHIVE);
        });
        _ui.logElem.addEventListener('click', () => {
            this._event.DispatchEvent(SettingEvent.EVT_SETTING_LOG);
        });
    }

    Show() {
        document.body.append(this._ui);
        this.myModal.show();
    }

    Hide(immediate = false) {
        this.myModal.hide();
        if (immediate) {
            this._ui.remove();
        }
    }
}

